﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Weight.Controls
{
    public class LYFTextBox : TextBox
    {
        public LYFTextBox()
        {
            this.DoubleBuffered = true;//设置本窗体
            this.SetStyle(
                      //ControlStyles.UserPaint |    //使用自定义的绘制方式
                      ControlStyles.ResizeRedraw//当控件大小发生变化时就重新绘制
                    | ControlStyles.SupportsTransparentBackColor//则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度
                    | ControlStyles.AllPaintingInWmPaint//则控件忽略窗口消息 WM_ERASEBKGND 以减少闪烁
                    | ControlStyles.OptimizedDoubleBuffer//则控件将首先绘制到缓冲区而不是直接绘制到屏幕，这可以减少闪烁
                    | ControlStyles.DoubleBuffer
                    , true);

            this.BorderStyle = BorderStyle.None;
        }

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        //private static extern IntPtr LoadLibrary(string lpFileName);

        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams prams = base.CreateParams;
        //        if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
        //        {
        //            prams.ExStyle |= 0x020; // transparent
        //            prams.ClassName = "RICHEDIT50W";// TRANSTEXTBOXW  RICHEDIT50W
        //        }
        //        return prams;
        //    }
        //}

        public void SetSkin(Color color)
        {
            this.BackColor = color;
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // CoolTextBox
            // 
            this.ResumeLayout(false);

        }

    }
}
